package com.lianzai.common.config;

import com.alibaba.fastjson.JSON;
import com.lianzai.common.sms.request.SmsSendRequest;
import com.lianzai.common.sms.util.ChuangLanSmsUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

/**
 * Created by IBM on 2018/11/6.
 */
@Slf4j
@Data
@Configuration
public class SendMailConfig {
    public static final String charset = "utf-8";

    @Value("${send253.account}")
    private String account;

    @Value("${send253.password}")
    private String password;

    @Value("${send253.url}")
    private String url;

    private String report = "true";

    /**
     * 发送注册短信验证码
     * @param code
     * @param phone
     */
    public void sendRegMsg(String code, String phone){
        String msg = "【湘泊客】你的注册验证码是: %s,验证码15分钟有效,请及时完成注册";

        SmsSendRequest smsSingleRequest = new SmsSendRequest(account, password, String.format(msg, code), phone, report);

        String result = ChuangLanSmsUtil.sendSmsByPost(url, JSON.toJSONString(smsSingleRequest));

        //log.info("发送注册短信验证码 code:{}, phone:{}, result:{}", code, phone, result);
    }
}
